import { Body, Controller, Ip, Post, Request } from '@nestjs/common';
import { AuthService } from './auth.service';
import { LoginUserDto } from './dto/login-user.dto';
import { LoginAuthDto } from './dto/login-auth.dto';
import { Public } from './utils/public.metadata';
import { getPlatform } from 'src/utils/getPlatform';
@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}

  @Public()
  @Post('login')
  async loginUser(
    @Body() loginUserDto: LoginUserDto,
    @Ip() ip: string,
    @Request() req: AuthRequest,
  ): Promise<LoginAuthDto> {
    const result = await this.authService.signIn(
      loginUserDto.email,
      loginUserDto.password,
      getPlatform(req.headers?.['user-agent']),
      ip,
    );

    return result;
  }
}
